package cn.wolfcode.crm.service.imp;


import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.IDepartmentService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override

    public void deleteByPrimaryKey(Long id) {
        if (id != null) {

        departmentMapper.deleteByPrimaryKey(id);
        }
    }

    @Override

    public void saveOrUpdate(Department record) {
        if (record.getId() != null) {
            //update
            departmentMapper.updateByPrimaryKey(record);
        }else {
            departmentMapper.insert(record);
        }
    }

    @Override
    public Department selectByPrimaryKey(Long id) {

            Department dept = departmentMapper.selectByPrimaryKey(id);
        return dept;

    }

    @Override
    public List<Department> selectAll() {
        List<Department> depts = departmentMapper.selectAll();
        return depts;
    }

    @Override//状态

    public void changeState(Long id) {
        departmentMapper.changeState(id);
    }




    @Override
    public PageResult queryForList(QueryObject qo) {
        int rows = departmentMapper.rows(qo);
        if (rows==0) {
            return PageResult.EMPTY_RESULT;
        }
        PageResult result =  new PageResult(rows,departmentMapper.queryForList(qo));
        return result;
    }


}
